$(function () {
    var layer = layui.layer;
    form = layui.form;
    // let ID = window.parent.Id
    let ID = location.search.split('=')[1]
    console.log(ID)
    axios({
        url: "http://localhost:8888/admin/users/" + ID,
        method: "GET",
        headers: {
            Authorization: sessionStorage.getItem('mytoken')
        }
    }).then(function (res) {
        var { username, nickname, email } = res.data.data
        $("input[name=username]").val(username)
        $("input[name=nickname]").val(nickname)
        $("input[name=email]").val(email)
    })

    // 点击提交
    $(".layui-form").on("submit", function (ev) {
        ev.preventDefault()
        var fd = $(this).serialize();
        var data = `${fd}&id=${ID}`;
        axios({
            url: "http://localhost:8888/admin/users",
            method: "PUT",
            data,
            headers: {
                Authorization: sessionStorage.getItem('mytoken')
            }
        }).then(function (res) {
            layer.msg(res.data.message)
        })
    })
})